{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "import smtplib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [],
   "source": [
    "smtpobj=smtplib.SMTP(\"smtp.163.com\",25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [],
   "source": [
    "from email.mime.text import MIMEText\n",
    "from email.header import Header"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [],
   "source": [
    "sender = 'wqs121212121@163.com'\n",
    "receivers = ['wqs116116@126.com'] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "mail_user=\"wqs121212121@163.com\"\n",
    "mail_pwd=\"LGMUPNHKJHHPYOED\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "message=MIMEText(\"this is a message for test and please ignore it\",'plain','utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "message['From']=sender\n",
    "message['To']=receivers[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "message['subject']=Header('test message!!','utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(235, b'Authentication successful')"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "smtpobj.login(mail_user,\"RVJEANFHGQXBRNBX\")  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<email.mime.text.MIMEText at 0x1628e332eb0>"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "邮件发送成功\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    smtpobj.sendmail(sender, receivers[0], message.as_bytes())\n",
    "    print(\"邮件发送成功\")\n",
    "except smtplib.SMTPException:\n",
    "    print(\"Error: 无法发送邮件\")"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "7852afdaf9e7274afa032eaec216d523779e02e5753aa07ac78ccb4bbaf816cb"
  },
  "kernelspec": {
   "display_name": "Python 3.8.6rc1 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6rc1"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
